package edu.chl.grupp11.aegas.controller.imp;

import javax.swing.JOptionPane;

import edu.chl.grupp11.aegas.controller.IErrorController;
import edu.chl.grupp11.aegas.view.MainView;

public class ErrorController implements IErrorController {
	private static ErrorController instance = new ErrorController();

	public static ErrorController getInstance() {
		return instance;
	}

	private ErrorController() {
		// Singleton scheisse
	}

	private void setErrorLabel(String text) {
		MainView.errorLabel.setText(text);
		MainView.errorLabel.repaint();
	}

	/**
	 * If no exception is specified the error message will be shown in the error
	 * label. Otherwise the error message will be shown in a popup.
	 * 
	 * @param exception
	 * @param text
	 */
	@Override
	public void setErrorMessage(Exception exception, String text) {
		if (exception == null) {
			setErrorLabel(text);
		} else {
			setMessagePopup("ERROR: " + exception.toString() + "\n" + text);
		}
	}

	private void setMessagePopup(String text) {
		JOptionPane.showMessageDialog(null, text);
	}

	/**
	 * This method is not used at the moment but it will maybe be used in the
	 * future. private String setInputPopup(String text) { return
	 * JOptionPane.showInputDialog(text); }
	 */
}
